package cn.topevery.garden.wapi.controller;

import cn.topevery.garden.dal.logic.BulletinFileLogic;
import cn.topevery.garden.dal.logic.SysDeptLogic1;
import cn.topevery.garden.entity.dto.BulletinFileDTO;
import cn.topevery.garden.entity.query.BulletinFileQuery;
import cn.topevery.garden.entity.vo.BulletinFileVO;
import cn.topevery.garden.entity.po.BulletinFile;
import hw.topevery.basis.dal.logic.SysDeptLogic;
import hw.topevery.basis.dal.logic.SysRoleLogic;
import hw.topevery.basis.dal.logic.SysUserExtLogic;
import hw.topevery.basis.dal.logic.SysUserLogic;
import hw.topevery.basis.entity.model.DeptTree;
import hw.topevery.basis.entity.po.SysDept;
import hw.topevery.framework.SystemConst;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.util.ExcelUtil;
import hw.topevery.framework.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.dozermapper.core.Mapper;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * 系统公告附件
 */
@Api(tags = "系统公告附件")
@RestController
@RequestMapping("/bulletinFile")
public class BulletinFileController extends BaseController {

    @Autowired
    private Mapper mapper;

    @Autowired
    BulletinFileLogic bulletinFileLogic;



    /**
     * 获取系统公告附件分页列表
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取系统公告附件页列表")
    @PostMapping("/listPage")
    public JsonResult<DataPager<BulletinFileVO>> listPage(@RequestBody BulletinFileQuery query) {
        return JsonResult.ok(bulletinFileLogic.listPage(query));
    }

    @ApiOperation("新增/编辑 系统公告附件信息")
    @PostMapping("/saveOrUpdate")
    public JsonResult<Boolean> saveOrUpdate(@Valid @RequestBody BulletinFileDTO dto) {
        bulletinFileLogic.saveOrUpdate(getUser().id.toString(),mapper.map(dto, BulletinFile.class));
        return JsonResult.ok(true);
    }

    @ApiOperation("通过Id获取详情")
    @GetMapping("/getInfoById")
    public JsonResult<BulletinFileVO> getInfoById(@RequestParam Integer id) {
        BulletinFile entity = bulletinFileLogic.getEntity(id);
        BulletinFileVO vo= mapper.map(entity, BulletinFileVO.class);
        return JsonResult.ok(vo);
    }

    @ApiOperation("根据自增ID批量删除")
    @PostMapping("/deleteBatchById")
    public JsonResult<Boolean> deleteBatchById(@RequestBody Integer[] ids) {
        bulletinFileLogic.deleteBatchById(getUser().id.toString(),ids);
        return JsonResult.ok(true);
    }

    @ApiOperation("导出系统公告附件信息")
    @GetMapping("/export")
    public void export(BulletinFileQuery query, HttpServletResponse response) {
        List<BulletinFileVO> list = bulletinFileLogic.listPage(query).records;
        ExcelUtil.exportExcel(list, "系统公告附件", "sheet1", BulletinFileVO.class, "系统公告附件", response);
    }
}
